package com.example.park_management.controller;



import com.example.park_management.entity.SeUser;
import com.example.park_management.entity.Sebei;
import com.example.park_management.result.R;
import com.example.park_management.service.SeUserService;
import com.example.park_management.service.SebeiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin
@RequestMapping("/seuser")
@RestController
public class seuserController {
    @Autowired
    SeUserService seUserService;
    @Autowired
    SebeiService sebeiService;
    @RequestMapping("/add")
    // SeUser 接收到的数据就是  userid sebei_id
    public R<String> add(SeUser seuser){
        System.out.println(seuser.getUserId());
        boolean a =  seUserService.save(seuser);
        //判断是否存到数据库 将用户id 和设备id
        if (a){
            Sebei sebei = new Sebei();
            sebei.setStatus(0);
            sebei.setId(seuser.getSeId());
            sebeiService.updateById(sebei);
            return R.success("设备出借成功");
        }
        return R.error("借出失败");
    }

    @RequestMapping("/delete")
    public R<String> delete(SeUser seuser){
        Sebei sebei = new Sebei();
        sebei.setId(seuser.getSeId());
        sebei.setStatus(1);
        sebeiService.updateById(sebei);
        Boolean a = seUserService.del(seuser);
        if (a){
            return R.success("归还成功");
        }
        return R.error("归还失败");
    }


}
